package com.itheima.day05.zuoye.ZuoYe5;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

public class test {
    private static ArrayList<Goods> list;
    public static void main(String[] args) {
        test.list = new ArrayList<Goods>();
        Goods g1 = new Goods("电脑", 5000);
        Goods g2 = new Goods("鼠标", 20);
        Goods g3 = new Goods("键盘", 50);
        Goods g4 = new Goods("显示器", 800);
        Goods g5 = new Goods("手机", 2000);
        list.add(g1);
        list.add(g2);
        list.add(g3);
        list.add(g4);
        list.add(g5);
        String TIEM = "2025-07-10 00:00:00";
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime time1 = LocalDateTime.of(2025, 7, 19, 0, 0);
        LocalDateTime time2 = LocalDateTime.parse(TIEM, dtf);
        test.miaosha(time1);
        test.miaosha(time2);
    }
    public static void miaosha(LocalDateTime X) {
        while (true){
            System.out.println("请输入你选择的商品：");
            Scanner sc = new Scanner(System.in);
            String goods = sc.next();
            Goods g = null;
            for (int i = 0; i < list.size(); i++) {
                if (goods.equals(list.get(i).getName())) {
                    g = list.get(i);
                    break;
                }
            }
            if (g == null) {
                System.out.println("秒杀失败，不存在该商品");
                return;}
            if (g.getCount()<=0){
                System.out.println("秒杀失败，该商品已售完");
                return;
            }

            if (X.isAfter(Goods.start)&& X.isBefore(Goods.end)) {
                System.out.println("秒杀成功");
                return;
            }else {
                System.out.println("秒杀失败，不在秒杀时间范围内");
                return;
            }
        }
    }




}
